package com.efuture.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassNAME JdbcModifyData
 * @Description 使用jdbc对account表进行数据修改
 * @Author zhaoshanshan
 * @Date 2021/9/19 6:11 下午
 * @Version 1.0
 */
public class JdbcModifyData {

    public static void main(String[] args) {
        Connection coon = null;
        Statement stmt = null;
        try{
            //注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接
            coon = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3","root","zhaoss");
            //定义sql
            String sql = "update account set balance = 2000 where id = 5";
            //获取执行sql的对象
            stmt = coon.createStatement();
            //执行sql
            int count = stmt.executeUpdate(sql);
            System.out.println("影响的行数:"+count);

        }catch (Exception e){
            e.printStackTrace();
        }finally {
           if(null!=coon){
               try {
                   coon.close();
               } catch (SQLException e) {
                   e.printStackTrace();
               }
           }
           if(null!=stmt){
               try {
                   stmt.close();
               } catch (SQLException e) {
                   e.printStackTrace();
               }
           }
        }

    }
}